package com.sky.mapper.user;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.pojo.Orders;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Description OrderMapper
 * @Author lyh
 * @Date 2024-10-11
 */
@Mapper
public interface OrderMapper {
    void save(Orders orders);

    @Update("update orders set pay_status=#{payStatus},status=#{status},checkout_time=#{checkoutTime} where number=#{number}")
    void updatePaySuccess(Orders orders);

    List<Orders> selectByStatusAndTime(@Param("status") Integer status, @Param("maxTime") Date maxTime, @Param("minTime") Date minTime);

    @Update("update orders set status=#{status} where id=#{id}")
    void updateOrdersStatusById(@Param("status") Integer status, @Param("id") Long id);

    Page<Orders> pageQuery(OrdersPageQueryDTO dto);

    @Select("select * from orders where id=#{orderId}")
    Orders getById(Long orderId);

    OrderVO getById1(Long orderId);


    void update(Orders orders);

    /**
     * 商家端分页查询
     *
     * @param dto
     * @return
     */
    Page<OrderVO> conditionSearch(OrdersPageQueryDTO dto);

    @Select("select count(*) from orders where status=#{status}")
    Integer countStatus(Integer status);

    @Select("select status,count(*) total from orders group by status")
    List<Map> selectStatus();

    OrderStatisticsVO selectStatus1();

    OrderVO adminOrderDetail(Long orderId);

    @Update("update orders set status=#{status},cancel_reason=#{cancelReason},cancel_time=#{cancelTime} where id=#{id}")
    void cancelingOrders(Orders orders);

    @Update("update orders set status=#{status} where number=#{outTradeNo}")
    void updateOrderCancelSuccess(@Param("status") Integer status, @Param("outTradeNo") String outTradeNo);

    @Update("update orders set status=#{status},rejection_reason=#{rejectionReason},cancel_time=#{cancelTime} where id=#{id}")
    void rejectioningOrders(Orders orders);

    @Update("update orders set status=#{status} where id=#{id}")
    void updateconfirm(Orders orders);

    @Update("update orders set status=#{status} where number=#{orderNumber}")
    void updateOrderByNumber(@Param("orderNumber") String orderNumber, @Param("status") Integer status);

    @Select("select * from orders where number=#{orderNumber}")
    OrderVO selectByOrderNumber(String orderNumber);
    Double countDayReport(String date);

    Map<String, BigDecimal> countReport(@Param("begin") String begin, @Param("end") String end, @Param("dateList") List<String> dateList);

    Long selectTotalOrderByDateAndStatus(@Param("begin") String begin, @Param("end") String end, @Param("status") Integer status);

    Map<String, Long> selectDayTotalOrderByDateAndStatus(@Param("dateList") List<String> dateList, @Param("begin") String begin, @Param("end") String end, @Param("status") Integer status);

    /**
     * 商品销量top10统计
     * @param begin
     * @param end
     * @return
     */
    List<Map<String,Object>> selectTop10(@Param("begin") String begin, @Param("end") String end);

    /**
     * 根据订单状态查询指定时间段的订单数
     * @param begin
     * @param end
     * @param status
     * @return
     */
    Integer selectDayByStatus(@Param("begin") String begin, @Param("end") String end, @Param("status") Integer status);

    /**
     * 统计今天总的营业额
     * @param begin
     * @param end
     * @return
     */
    Double totalAmountDay(@Param("begin") String begin, @Param("end") String end);
}
